package com.fund.datacopy.utils;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

public class DataCopyUtil {
	public static void copy(DBCollection srcConn, DBCollection destConn, BasicDBObject q) {
		try {
			List<DBObject> array = srcConn.find(q).toArray();
			if (CollectionUtils.isEmpty(array)) {
				System.out.println(srcConn.getName() + " execute query [" + q.toString() + "] no data found");
				return;
			}
			destConn.remove(q);
			destConn.insert(array);
			System.out.println(srcConn.getName() + " execute query [" + q.toString() + "] done");
		} catch (Exception e) {
			System.out.println("copy .. failure");
			e.printStackTrace();
		}
	}
}
